package com.thwj.project.app.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.thwj.framework.web.domain.R;
import com.thwj.framework.web.service.TokenService;
import com.thwj.project.app.api.param.UserAccountWithdrawParam;
import com.thwj.project.app.api.vo.UserAccountInOutVo;
import com.thwj.project.app.api.vo.UserAccountVo;
import com.thwj.project.app.service.AppAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags="app 账户相关接口")
@RestController
@RequestMapping("/app/account")
public class AppAccountController {


    @Autowired
    private AppAccountService appAccountService;
    @Autowired
    private TokenService tokenService;


    @ApiOperation(value = "获取当前用户的账户数据",notes = "获取当前用户的账户数据")
    @GetMapping("/getUserAccount")
    public R<UserAccountVo> getUserAccount() {
        UserAccountVo accountVo = appAccountService.getUserAccount(tokenService.getLoginUser());
        return R.data(accountVo);
    }

    @ApiOperation(value = "获取当前用户的账户明细列表",notes = "获取当前用户的账户明细列表")
    @GetMapping("/getUserAccountInOutPage")
    public R<Page<UserAccountInOutVo>> getUserAccountInOutPage(Page page) {
        Page<UserAccountInOutVo> inOutPage = appAccountService.getUserAccountInOutPage(page,tokenService.getLoginUser());
        return R.data(inOutPage);
    }

    @ApiOperation(value = "发起提现申请操作",notes = "发起提现申请操作")
    @PostMapping("/commitWithdrawAudit")
    public R<String> commitWithdrawAudit(@RequestBody UserAccountWithdrawParam withdrawParam) {
        appAccountService.commitWithdrawAudit(withdrawParam,tokenService.getLoginUser());
        return R.data("操作成功，等待审核");
    }


}
